package com.hkts.management.shippercomment.controller;


import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hkts.management.common.utils.Result;
import com.hkts.management.common.utils.ResultUtil;
import com.hkts.management.utils.CustomPageUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.GetMapping;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.hkts.management.shippercomment.service.IShipperCommentService;
import com.hkts.management.shippercomment.entity.ShipperComment;

import java.util.List;

/**
 * @author hml
 * @since 2021-05-20
 */
@RestController
@RequestMapping("/order/shipperComment")
@Api(tags = "司机评论信息管理接口")
public class ShipperCommentController {
    private final Logger logger = LoggerFactory.getLogger(ShipperCommentController.class);

    @Autowired
    public IShipperCommentService iShipperCommentService;

    /**
     * 分页查询数据
     *
     * @param page           分页信息
     * @param shipperComment 查询条件
     * @return
     */
    @ResponseBody
    @GetMapping("/getShipperCommentPageList")
    public Result<Object> getHontUserList(Page<ShipperComment> page, ShipperComment shipperComment) {
        return ResultUtil.data(CustomPageUtils.getCustomPage(iShipperCommentService.selectPage(page, shipperComment)));
    }

    /**
     * 保存和修改公用的
     *
     * @param shipperComment 传递的实体
     * @return saveOrUpdate
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/shipperCommentSave")
    @ApiOperation(value = "添加司机评论")
    public Result<Object> shipperCommentSave(ShipperComment shipperComment) {
        iShipperCommentService.saveOrUpdate(shipperComment);
        return ResultUtil.success("保存成功");
    }

    /**
     * 根据id获取对象
     *
     * @param id 实体ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.GET, value = "/shipperCommentGetById")
    public Result<Object> shipperCommentGetById(String id) {
        ShipperComment byId = iShipperCommentService.getById(id);
        return ResultUtil.data(byId);
    }

    /**
     * 根据id删除对象
     *
     * @param id 实体ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/shipperCommentDelete")
    public Result<Object> hontUserDelete(String id) {
        iShipperCommentService.removeById(id);
        return ResultUtil.success("删除成功");
    }

    /**
     * 批量删除对象
     *
     * @param item 实体集合ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/shipperCommentBatchDelete")
    public Result<Object> deleteBatchIds(String item) {
        List<String> ids = (List<String>) JSON.parse(item);
        iShipperCommentService.removeByIds(ids);
        return ResultUtil.success("删除成功");
    }

}
